package noncomunicating.classes.SSI;

import java.util.HashMap;

import util.Regex;

import comunicating.classes.ServerLoop;

import noncomunicating.classes.Request;


public class Echo extends Directive{
	private HashMap<String, String> variables = new HashMap<String, String>();
	
	private void setVariables(){
		Request request = this.getRequest(); //TODO add more variable types for echo
		variables.put("CONTENT_TYPE", request.getDataType(0)+"/"+request.getDataType(1));
		variables.put("HTTP_STATUS", request.getStatus());
		variables.put("HTTP_ALL", request.getHttpRequest());
		variables.put("SERV_VERBOSE", Boolean.toString(ServerLoop.verbose));
		variables.put("SERV_DIRECTORY", ServerLoop.directory);
		variables.put("SERV_PORT", Integer.toString(ServerLoop.getPort()));
		variables.put("SERV_TIME", ServerLoop.getTimeString());
		variables.putAll(request.getHeaderData());
		
	}
	
	public Echo(String cmt, SSIParser parser) {
		super(cmt, parser);
		setVariables();
		String var = Regex.firstMatch("\"\\S*\"", cmt).replace("\"", "");
		
		if (variables.containsKey(var)){
			this.subTag(cmt, variables.get(var));
		}
		else{
			this.subTag(cmt, "<!-- Variable Not Found -->");
		}
		
	}

}
